// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.randomizedWorld.randomizedVehicleStory;

import java.util.ArrayList;
import zombie.core.Rand;
import zombie.core.math.PZMath;
import zombie.iso.IsoChunk;
import zombie.iso.IsoDirections;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoMetaGrid;
import zombie.iso.IsoObject;
import zombie.iso.Vector2;
import zombie.vehicles.BaseVehicle;

public final class RVSConstructionSite extends RandomizedVehicleStoryBase {
    private ArrayList<String> tools = null;

    public RVSConstructionSite() {
        this.name = "Construction Site";
        this.minZoneWidth = 6;
        this.minZoneHeight = 6;
        this.setChance(3);
        this.tools = new ArrayList();
        this.tools.add("Base.PickAxe");
        this.tools.add("Base.Shovel");
        this.tools.add("Base.Shovel2");
        this.tools.add("Base.Hammer");
        this.tools.add("Base.LeadPipe");
        this.tools.add("Base.PipeWrench");
        this.tools.add("Base.Sledgehammer");
        this.tools.add("Base.Sledgehammer2");
    }

    @Override
    public void randomizeVehicleStory(IsoMetaGrid.Zone zone, IsoChunk chunk) {
        this.callVehicleStorySpawner(zone, chunk, 0.0F);
    }

    @Override
    public boolean initVehicleStorySpawner(IsoMetaGrid.Zone zone, IsoChunk chunk, boolean debug) {
        VehicleStorySpawner vehicleStorySpawner = VehicleStorySpawner.getInstance();
        vehicleStorySpawner.clear();
        boolean _boolean = Rand.NextBool(2);
        if (debug) {
            _boolean = true;
        }

        int int0 = _boolean ? 1 : -1;
        Vector2 vector2 = IsoDirections.N.ToVector();
        float float0 = (float) (Math.PI / 6);
        if (debug) {
            float0 = 0.0F;
        }

        vector2.rotate(Rand.Next(-float0, float0));
        vehicleStorySpawner.addElement("vehicle1", (float)(-int0) * 2.0F, 0.0F, vector2.getDirection(), 2.0F, 5.0F);
        float float1 = 0.0F;
        vehicleStorySpawner.addElement("manhole", (float)int0 * 1.5F, 1.5F, float1, 3.0F, 3.0F);
        int int1 = Rand.Next(0, 3);

        for (int int2 = 0; int2 < int1; int2++) {
            float1 = 0.0F;
            vehicleStorySpawner.addElement("tool", (float)int0 * Rand.Next(0.0F, 3.0F), -Rand.Next(0.7F, 2.3F), float1, 1.0F, 1.0F);
        }

        vehicleStorySpawner.setParameter("zone", zone);
        return true;
    }

    @Override
    public void spawnElement(VehicleStorySpawner spawner, VehicleStorySpawner.Element element) {
        IsoGridSquare isoGridSquare0 = element.square;
        if (isoGridSquare0 != null) {
            float float0 = PZMath.max(element.position.x - (float)isoGridSquare0.x, 0.001F);
            float float1 = PZMath.max(element.position.y - (float)isoGridSquare0.y, 0.001F);
            float float2 = 0.0F;
            float float3 = element.z;
            IsoMetaGrid.Zone zone = spawner.getParameter("zone", IsoMetaGrid.Zone.class);
            BaseVehicle baseVehicle = spawner.getParameter("vehicle1", BaseVehicle.class);
            String string0 = element.id;
            switch (string0) {
                case "manhole":
                    isoGridSquare0.AddTileObject(IsoObject.getNew(isoGridSquare0, "street_decoration_01_15", null, false));
                    IsoGridSquare isoGridSquare1 = isoGridSquare0.getAdjacentSquare(IsoDirections.E);
                    if (isoGridSquare1 != null) {
                        isoGridSquare1.AddTileObject(IsoObject.getNew(isoGridSquare1, "street_decoration_01_26", null, false));
                    }

                    isoGridSquare1 = isoGridSquare0.getAdjacentSquare(IsoDirections.W);
                    if (isoGridSquare1 != null) {
                        isoGridSquare1.AddTileObject(IsoObject.getNew(isoGridSquare1, "street_decoration_01_26", null, false));
                    }

                    isoGridSquare1 = isoGridSquare0.getAdjacentSquare(IsoDirections.S);
                    if (isoGridSquare1 != null) {
                        isoGridSquare1.AddTileObject(IsoObject.getNew(isoGridSquare1, "street_decoration_01_26", null, false));
                    }

                    isoGridSquare1 = isoGridSquare0.getAdjacentSquare(IsoDirections.N);
                    if (isoGridSquare1 != null) {
                        isoGridSquare1.AddTileObject(IsoObject.getNew(isoGridSquare1, "street_decoration_01_26", null, false));
                    }
                    break;
                case "tool":
                    String string1 = (String)this.tools.get(Rand.Next(this.tools.size()));
                    isoGridSquare0.AddWorldInventoryItem(string1, float0, float1, float2);
                    break;
                case "vehicle1":
                    baseVehicle = this.addVehicle(
                        zone, element.position.x, element.position.y, float3, element.direction, null, "Base.PickUpTruck", null, "ConstructionWorker"
                    );
                    if (baseVehicle != null) {
                        this.addZombiesOnVehicle(Rand.Next(2, 5), "ConstructionWorker", Integer.valueOf(0), baseVehicle);
                        this.addZombiesOnVehicle(1, "Foreman", Integer.valueOf(0), baseVehicle);
                        spawner.setParameter("vehicle1", baseVehicle);
                    }
            }
        }
    }
}
